package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.VideoVo;
import com.tanhua.server.service.SmallVideoService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 小视频控制层
 */
@RestController
@RequestMapping("/smallVideos")
public class SmallVideoController {

    @Autowired
    private SmallVideoService smallVideoService;

    /**
     * 发布小视频
     * videoThumbnail:视频封面文件
     * videoFile:视频文件
     */
    @PostMapping
    public ResponseEntity addVideo(MultipartFile videoThumbnail,MultipartFile videoFile){
        smallVideoService.addVideo(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }


    /**
     * 小视频列表
     */
    @GetMapping
    public ResponseEntity findPageVideo(@RequestParam(value = "page",defaultValue = "1") Long page, @RequestParam(value = "pagesize",defaultValue = "10")Long pageSize){
        PageResult<VideoVo> pageResult = smallVideoService.findPageVideo(page,pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 視頻點贊
     * @param id
     * @return
     */
    @PostMapping("/{id}/like")
    public void addLike(@PathVariable String id){
        ObjectId objectId = new ObjectId(id);
        smallVideoService.updateVideo(objectId,"like");
    }

    /**
     * 視頻點贊取消
     * @param id
     */
    @PostMapping("/{id}/dislike")
    public void dislike(@PathVariable String id){
        ObjectId objectId = new ObjectId(id);
        smallVideoService.updateVideo(objectId,"dislike");
    }
//    /**
//     * 視頻添加評論
//     * @param id
//     * @return
//     */
//    @PostMapping("/{id}/comments")
//    public void addComments(@PathVariable ObjectId id){
//        smallVideoService.addLike(id,"comments");
//    }
//    /**
//     * 視頻添加喜歡
//     * @param id
//     * @return
//     */
//    @PostMapping("/{id}/userFocus")
//    public void userFocus(@PathVariable String id){
//        ObjectId objectId = new ObjectId(id);
//        smallVideoService.updateVideo(objectId,"userFocus");
//    }
//
//    /**
//     * 視頻取消喜歡
//     * @param id
//     */
//    @PostMapping("/{id}/userUnFocus")
//    public void userUnFocus(@PathVariable String id){
//        ObjectId objectId = new ObjectId(id);
//        smallVideoService.updateVideo(objectId,"userUnFocus");
//    }
}
